///*
//package com.example.demo.google;
//
//import com.google.ads.googleads.lib.GoogleAdsClient;
//import com.google.ads.googleads.v3.resources.BiddingStrategy;
//import com.google.ads.googleads.v3.resources.Campaign;
//import com.google.ads.googleads.v3.resources.CampaignBudget;
//import com.google.ads.googleads.v3.resources.ChangeStatus;
//import com.google.ads.googleads.v3.services.*;
//import com.google.api.gax.rpc.ServerStream;
//import com.google.auth.Credentials;
//import com.google.auth.oauth2.UserCredentials;
//
//import java.util.Optional;
//
//*/
///**
// * @author ljh
// * @create 2020/4/14
// * @describe
// *//*
//
//public class GoogleTest {
//
//    private static final int PAGE_SIZE = 1_0000;
//
//    */
///*public static void main(String[] args) {
//        String ss="customers/9819655303/campaigns/1636954303";
//        String[] ss2=ss.split("/");
//        System.out.println(ss2[ss2.length-1]);
//    }*//*
//
//
//    public static void main(String[] args) {
//        Long customerId = Long.parseLong("9819655303");
//        Long managerCustomerId = Long.parseLong("5179571058");
//
//        // test customerId
////			Long customerId = Long.parseLong("9819655303");
////			Long managerCustomerId = Long.parseLong("5179571058");
//        String clientId = "432767459960-2e21envvbpeihtv4auqaioph1174f8i3.apps.googleusercontent.com";
//        String clientSecret = "i5eD25HIUvvaq6-9FkH17xDI";
//        String refreshToken = "1//0gCKR02HHoGx5CgYIARAAGBASNwF-L9IruLegSCUQfqNeEtdA9qnUuge1W-l5CIvYSMwrCy5Pv-UmCAZb8sfX-CAGYGR-BhxSUR0";
//        String developToken = "gUeEor3uS2Mql15wHTncEA";
//        Credentials credentials =
//                UserCredentials.newBuilder()
//                        .setClientId(clientId)
//                        .setClientSecret(clientSecret)
//                        .setRefreshToken(refreshToken)
//                        .build();
//
//        GoogleAdsClient googleAdsClient =
//                GoogleAdsClient.newBuilder()
//                        .setCredentials(credentials)
//                        .setDeveloperToken(developToken)
//                        .setLoginCustomerId(managerCustomerId)
//                        .build();
//        GoogleAdsServiceClient googleAdsServiceClient = googleAdsClient.getLatestVersion().createGoogleAdsServiceClient();
//        String searchQuery = "SELECT campaign.id, campaign.name,campaign.status," +
//                "campaign.serving_status,campaign.advertising_channel_type,campaign.advertising_channel_sub_type," +
//                "campaign.ad_serving_optimization_status,campaign.bidding_strategy_type," +
//                "campaign.start_date,campaign.end_date," +
//                "campaign_budget.id,campaign_budget.name,campaign_budget.amount_micros," +
//                "campaign_budget.total_amount_micros,campaign_budget.status,campaign_budget.delivery_method," +
//                "campaign_budget.explicitly_shared," +
//                "bidding_strategy.id,bidding_strategy.name,bidding_strategy.status," +
//                "bidding_strategy.type,bidding_strategy.enhanced_cpc," +
//                "bidding_strategy.target_cpa.cpc_bid_ceiling_micros," +
//                "bidding_strategy.target_cpa.cpc_bid_floor_micros," +
//                "bidding_strategy.target_cpa.target_cpa_micros," +
//                "bidding_strategy.target_impression_share.cpc_bid_ceiling_micros," +
//                "bidding_strategy.target_impression_share.location," +
//                "bidding_strategy.target_impression_share.location_fraction_micros," +
//                "bidding_strategy.target_roas.target_roas," +
//                "bidding_strategy.target_roas.cpc_bid_ceiling_micros," +
//                "bidding_strategy.target_roas.cpc_bid_floor_micros," +
//                "bidding_strategy.target_spend.target_spend_micros," +
//                "bidding_strategy.target_spend.cpc_bid_ceiling_micros," +
//                "campaign.app_campaign_setting.app_id, " +
//                "campaign.app_campaign_setting.app_store," +
//                "campaign.app_campaign_setting.bidding_strategy_goal_type"+
//                "  FROM campaign  ORDER BY campaign.id";
//        String searchQuery2 =
//                "SELECT change_status.resource_name, "
//                        + "change_status.last_change_date_time, "
//                        + "change_status.resource_type, "
//                        + "change_status.campaign, "
//                        + "change_status.ad_group, "
//                        + "change_status.resource_status, "
//                        + "change_status.ad_group_ad, "
//                        + "change_status.ad_group_criterion, "
//                        + "change_status.campaign_criterion "
//                        + "FROM change_status where change_status.last_change_date_time >= '2020-04-15' "
//                        + "ORDER BY change_status.last_change_date_time";
//        SearchGoogleAdsRequest request = SearchGoogleAdsRequest.newBuilder().setCustomerId(Long.toString(customerId))
//                .setPageSize(PAGE_SIZE).setQuery(searchQuery2).build();
//        GoogleAdsServiceClient.SearchPagedResponse searchPagedResponse = googleAdsServiceClient.search(request);
//        for (GoogleAdsRow googleAdsRow : searchPagedResponse.iterateAll()) {
//            Campaign campaign=googleAdsRow.getCampaign();
//            System.out.printf(
//                    "Campaign with ID %d and name '%s' and status %s and serving_status %s " +
//                            "and advertising_channel_type %s advertising_channel_sub_type %s " +
//                            "and ad_serving_optimization_status %s and start_date %s " +
//                            "and  end_date %s and bidding_strategy_type %s " +
//                            "and bidding_strategy %s campaign_budget %s was found.%n",
//                    campaign.getId().getValue(),
//                    campaign.getName().getValue(),
//                    campaign.getStatus().getNumber(),
//                    campaign.getServingStatus().getNumber(),
//                    campaign.getAdvertisingChannelType().getNumber(),
//                    campaign.getAdvertisingChannelSubType().getNumber(),
//                    campaign.getAdServingOptimizationStatus().getNumber(),
//                    campaign.getStartDate().getValue(),
//                    campaign.getEndDate(),
//                    campaign.getBiddingStrategyType().getNumber(),
//                    campaign.getBiddingStrategy().getValue(),
//                    campaign.getCampaignBudget());
//            CampaignBudget campaignBudget =googleAdsRow.getCampaignBudget();
//            System.out.printf("Campaign  budget  %s %n",campaignBudget);
//            BiddingStrategy biddingStrategy= googleAdsRow.getBiddingStrategy();
//            System.out.printf("biddingStrategy %s %n",biddingStrategy);
//            Campaign.AppCampaignSetting appCampaignSetting=googleAdsRow.getCampaign().getAppCampaignSetting();
//            appCampaignSetting.getAppStore();
//            System.out.printf("appCampaignSetting %s %n",appCampaignSetting);
//        }
//        for (GoogleAdsRow row : searchPagedResponse.iterateAll()) {
//            //System.out.printf("cap id %s",row.getChangeStatus().getCampaign().getValue());;
//            Optional<String> resourceNameOfChangedEntity =
//                    getResourceNameForResourceType(row.getChangeStatus());
//
//            System.out.printf(
//                    "On '%s', change status '%s' shows a resource type of '%s' "
//                            + "with resource name '%s' was '%s'.%n",
//                    row.getChangeStatus().getLastChangeDateTime().getValue(),
//                    row.getChangeStatus().getResourceName(),
//                    row.getChangeStatus().getResourceType().name(),
//                    resourceNameOfChangedEntity.orElse(""),
//                    row.getChangeStatus().getResourceStatus().name());
//        }
//    }
//    private static Optional<String> getResourceNameForResourceType(ChangeStatus changeStatus) {
//        String resourceName = null;
//        // This is the list of all known resource names but may be subject to change in the future.
//        // See https://developers.google.com/google-ads/api/docs/change-status for a description.
//        switch (changeStatus.getResourceType()) {
//            case AD_GROUP:
//                resourceName = changeStatus.getAdGroup().getValue();
//                break;
//            case AD_GROUP_AD:
//                resourceName = changeStatus.getAdGroupAd().getValue();
//                break;
//            case AD_GROUP_CRITERION:
//                resourceName = changeStatus.getAdGroup().getValue();
//                break;
//            case CAMPAIGN:
//                resourceName = changeStatus.getCampaign().getValue();
//                break;
//            case CAMPAIGN_CRITERION:
//                resourceName = changeStatus.getCampaignCriterion().getValue();
//                break;
//        }
//        return Optional.ofNullable(resourceName);
//    }
//}
//*/
